#ifndef DRAWTASK_H
#define DRAWTASK_H

#include "KmyStructDef.h"

class KmyITexture;
//class GLWidget;

class DrawTask
{
public:
    DrawTask();
//    DrawTask(KmyImages *kmyimages, int img_id,
//             int dx, int dy, float z,
//             float alpha, int angle, bool flip);

    DrawTask(KmyITexture *tex,
             int sx, int sy, int sw, int sh,
             int dx, int dy, int dw, int dh,
             int z,
             float alpha, float angle, int flip);

    DrawTask(KmyITexture *tex,
             int sx1, int sy1, int sx2, int sy2, int sx3, int sy3,
             int dx1, int dy1, int dx2, int dy2, int dx3, int dy3,
             int z, float alpha);

    DrawTask(KmyITexture *tex,
             int num, St_Rect* srects,
             St_Rect2* drects,
             int z, float alpha, float angle);

    DrawTask(KmyITexture *tex,
             St_Rect* srect,
             int dnum, St_Rect2* drects,
             int z, float alpha, float angle);

    virtual ~DrawTask();

//    void render(GLWidget *g);

    KmyITexture *tex;

//    bool is_region;

    static const int DRAW_TYPE_IMAGE_FULL = 0;          //整图 (废弃
    static const int DRAW_TYPE_IMAGE_REGION = 1;        //图的一部分
    static const int DRAW_TYPE_IMAGE_TRIANGLE = 2;      //三角形
    static const int DRAW_TYPE_IMAGE_PLURAL = 3;        // 多个图

    static const int DRAW_TYPE_GEOMETRY_LINE = 10;      //画线    （未实装
    static const int DRAW_TYPE_GEOMETRY_POLYGON = 11;   //画多边形 （未实装
    static const int DRAW_TYPE_GEOMETRY_FILL = 12;      //填充的多边形 （未实装

    int draw_type;
//    int tri_num_s;
//    St_Triangle *tris_s;

//    int tri_num_d;
//    St_Triangle *tris_d;

//    St_Rect *srects;
//    int sx, sy, sw, sh;
//    int dx, dy, dw, dh;
    float z;
    float alpha;
    float angle;

    int point_num;
    float* texcroods;
    float* vertices;
//    int flip;

    bool uv_updated;
    virtual void updateTexture(KmyITexture *tex);

    virtual void updateRegion(int sx, int sy, int sw, int sh,
                              int dx, int dy, int dw, int dh,
                              int z, float angle, int flip);

    virtual void updatePlural(int num, St_Rect* srects,
                              St_Rect2* drects,
                              int z, float alpha, float angle);
    virtual void updatePlural(St_Rect* srect, int num, St_Rect2* drects,
                              int z, float alpha, float angle);

    virtual void updateAlpha(float alpha);

    virtual void updateAngle(float angle);

protected:
    virtual void rectToTri_s(KmyITexture *tex, int x, int y, int w, int h,
                          int flip, St_Triangle *tri);
    virtual void rectToTri_d(int x, int y, int w, int h,
                          St_Triangle* tri);

    void toVertexAttribBuff(int tri_num, St_Triangle* tris_s, St_Triangle *tris_d);

    void toVertexAttribBuff(St_Triangle* tris_s, int tri_num, St_Triangle *tris_d);
};

class DrawTaskChainNode
{
public:
    DrawTaskChainNode(DrawTask* dt);

    DrawTask* dt;
    DrawTaskChainNode* pre;
    DrawTaskChainNode* next;
};

#endif // DRAWTASK_H
